using System;

namespace SmartBoard.Core.BaseObjects
{
    /// <summary>
    /// Base class for finalizable objects.
    /// </summary>
    public abstract class Finalizable : Disposable
    {
        ~Finalizable()
        {
            Free(false);
        }
    
        /// <summary>
        /// Disposes object resources.
        /// </summary>
        public new void Dispose()
        {
            lock (this)
            {
                if (!IsDisposed)
                {
                    try
                    {
                        Free(true);
                    }
                    finally
                    {
                        IsDisposed = true;
                        GC.SuppressFinalize(this);
                    }
                }
            }
        }
    }
}